package org.darkforest.ucenter.service.impl;

import java.util.List;
import java.util.Map;

import org.darkforest.dao.mapper.FavoritesMapper;
import org.darkforest.model.Favorites;
import org.darkforest.model.FavoritesSearchBean;
import org.darkforest.ucenter.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * 项目名称         :bwmall-ucenter
 * 文件名           :FavoritesServiceImpl.java
 * 开发公司及作者    :陈超
 * 版本号及开发日期  :Rev. 1.00 (2015年2月18日)
 */
@Service
public class FavoritesServiceImpl implements FavoritesService {
	
	@Autowired
	private FavoritesMapper favoritesMapper;

	@Override
	public void getFavoritesGoods(FavoritesSearchBean bean) {
		bean.setType("goods");
		bean.setResultList(favoritesMapper.selectByGoodByMember(bean));
	}
	@Override
	public void getFavoritesStore(FavoritesSearchBean bean) {
		bean.setType("store");
		bean.setResultList(favoritesMapper.selectByGoodByMember(bean));
	}

	@Override
	public void delFavorites(Map p) {
		if("goods".equals(p.get("type"))){
			favoritesMapper.updateGoodsFavoritesCountByIds(p);
		}else{
			favoritesMapper.updateStoreFavoritesCountByIds(p);
		}
		favoritesMapper.deleteByIds(p);
		
	}

	@Override
	public int addFavorites(Favorites favorites) {
		return favoritesMapper.insert(favorites);
	}

	@Override
	public List<Favorites> findFavoritesByCondtion(Favorites favorites) {
		return favoritesMapper.findFavoritesByCondtion(favorites);
	}

}
